<?php
namespace App\Api;

use App\Model\WALLETIOC;
use PhalApi\Api;
use App\Common\WalletBase;
use App\Model\WALLETADDRESS;

/**
 * Class WalletSet
 * @package App\Api
 * 临时修改变量设置钱包
 */

class WalletSet extends Api
{
    /**
     * 发币
     */
    public function getRules()
    {
            return
            [
                '*' => [
                    'token' => ['name' => 'token', 'require' => false],
                ],
            ];
    }
    public function putOut()
    {
        $name = 'BYBTEST';                         //发送币名
        $address = '0xc66cd3deec506713d653681c7663f2c4fe96fb3f';            //发送钱包地址
        $num = 100000000;                   //发送个数
        $decimal = 9;                      //小数点
        $privateKey = '0x605297a0025b7b6bff5b7d219e78cd4f7c4dce928e86069d64c99a47547aa1e9';  //私钥
        $issue = WalletBase::fundIssue($name, $address, $num, $decimal, $privateKey);
        if($issue->success == 'true')
        {
            $hash = $issue->data->hash;
            $receipt = WalletBase::transactionReceipt($hash);
            if($receipt->success)
            {
                $contractAddress = $receipt->data->contractAddress;
                $data = WalletBase::fundSave($name, $contractAddress);
                if($data->success)
                {
                    echo '发币成功';
                    WalletBase::currencies($name, $receipt->data->contractAddress, $decimal);
                    die;
                }
            }
        }
    }

    /**
     * 发币后转账到公司账户地址
     */
    public function fundTransfer()
    {
        $data = WalletBase::fundTransfer('BYBTSS', '0xbc87a6b9a4f8f746c2670aa7b392f2f87e378231', '100000000000','0x605297a0025b7b6bff5b7d219e78cd4f7c4dce928e86069d64c99a47547aa1e9');
        var_dump($data);die;
    }

    /**
     * 提币规则,  每个币都需设置, gas费
     * params 币 费率 最大矿工费 最小转账金额 最小矿工费
     */
    public function withdrawRules()
    {
        $data = WalletBase::withdrawRules('BYBTSS', '0.01', '10', '0.00001', '0.00001');
        var_dump($data);
    }

    public function deposit()
    {
        $wallet = new WALLETADDRESS();
        $wallet = $wallet->getAllWallet();
        $ico = new WALLETIOC();
        $ico = $ico->getAllIoc();
        foreach($ico as $v)
        {
            foreach($wallet as $w)
            {
                WalletBase::deposit($w['wallet_userid'], $v['ico']);
            }
        }
    }

    /**
     * 使钱包支持别的币  (合约地址填写该币的合约地址)
     */
    public function currencies()
    {
        if($this->token)
        {
            shell_exec('rm '.$this->token);
        }
        WalletBase::currencies('BNB', '0xB8c77482e45F1F44dE1745F52C74426C631bDD52', '18');
    }
}